package camid.test.testobjects;

import java.io.Serializable;

import camid.distribution.lifecycle.LifecycleScope;
import camid.distribution.lifecycle.ManagedObject;


@ManagedObject( lifecycleScope = LifecycleScope.PER_CLIENT )
public class IntegerBuffer implements IIntegerBuffer,Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7774637627135501274L;
	private Integer value;
	
	/* (non-Javadoc)
	 * @see camid.test.testobjects.IIntegerBuffer#set(java.lang.Integer)
	 */
	public void set(Integer value)
	{
		this.value = value;
	}
	
	/* (non-Javadoc)
	 * @see camid.test.testobjects.IIntegerBuffer#get()
	 */
	public Integer get()
	{
		return this.value;
	}
	
	/* (non-Javadoc)
	 * @see camid.test.testobjects.IIntegerBuffer#getAndSet(java.lang.Integer)
	 */
	public Integer getAndSet(Integer newValue)
	{
		Integer oldValue = value;
		value = newValue;
		return oldValue;
	}
	
	/* (non-Javadoc)
	 * @see camid.test.testobjects.IIntegerBuffer#getAndIncrement()
	 */
	public Integer getAndIncrement()
	{
		int oldValue = value;
		value++;
		return oldValue;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		IntegerBuffer other = (IntegerBuffer) obj;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}

	
	
}
